package com.my.batis.ctrl;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

import com.my.batis.entiy.UserInfo;
import com.my.batis.mapper.UserInfoMapper;
import com.my.batis.service.UserInfoService;

@Controller
public class UserInfoCtrl {
	Logger logger = Logger.getRootLogger();

	@Autowired
	private UserInfoService userInfoService;
	@Autowired
	private UserInfoMapper userInfoMapper;
	
	@RequestMapping("/user/index")
	public String index(){
		return "/user/index";
	}
	@RequestMapping("/user/add")
	public String add(UserInfo userInfo){
		userInfo.setStatus(0);
		userInfo.setUpdateTime(new Date());
		userInfo.setCreateTime(new Date());
		userInfoService.insert(userInfo);
		return "/user/index";
	}
	@RequestMapping("/user/list")
	@ResponseBody
	public List<UserInfo> list(HttpServletRequest request,UserInfo userInfo){
		List<UserInfo> list = userInfoMapper.getAll(null);
		logger.info("test");
		System.out.println("i am list");
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return userInfoService.getAll(null);
	}
}
